﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Marker
{
    public class PointType : ConfigurationElement
    {
        private static readonly ConfigurationProperty _name;

        [ConfigurationProperty("name", IsRequired = true)]
        public string Name
        {
            get
            {
                return this["name"] as string;
            }
            set
            {
                this["name"] = value;
            }
        }
    }

    [ConfigurationCollection(typeof(PointType))]
    public class Types : ConfigurationElementCollection
    {
        public PointType this[int index]
        {
            get
            {
                return base.BaseGet(index) as PointType;
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }

        public void Add(PointType element)
        {
            base.BaseAdd(element);
        }

        protected override System.Configuration.ConfigurationElement CreateNewElement()
        {
            return new PointType();
        }

        protected override object GetElementKey(System.Configuration.ConfigurationElement element)
        {
            return ((PointType)element).Name;
        }
    }


    public class PointTypesConfig : ConfigurationSection
    {

        public static PointTypesConfig GetConfig()
        {
            return (PointTypesConfig)System.Configuration.ConfigurationManager.GetSection("PointTypesConfig") ?? new PointTypesConfig();
        }



        [System.Configuration.ConfigurationProperty("Types")]
        public Types Types
        {
            get
            {
                object o = this["Types"];
                return o as Types;
            }
        }

    }
}
